package protocol.JT905_2014;

import java.util.HashMap;

public class Handle905_2014JT08 implements IHandle905_2014JT {
    @Override
    public String handle(JT_905_2014Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle0800(cmd);
            case 0x02:
                return handle0802(cmd);
            case 0x05:
                return handle0805(cmd);
            case 0x06:
                return handle0806(cmd);
            default:
                return "905:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle0806(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:音视频上传");
        builder.append("\r\n");
        builder.append("存储图像/音视频上传命令流水号:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("音视频ID:"+cmd.readInt(4));
        builder.append("\r\n");

        builder.append("位置/音视频数据大小:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("起始位置:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("数据包:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0805(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:存储音频检索应答");
        builder.append("\r\n");
        builder.append("应答流水号:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("检索总项数据包大小:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("当前检索项在总项数据中的偏移量:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("检索项:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0802(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:存储图像检索应答");
        builder.append("\r\n");
        builder.append("应答流水号:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("检索总项数据包大小:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("当前检索项在总项数据中的偏移量:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("检索项:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0800(JT_905_2014Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:摄像头图像上传");
        builder.append("\r\n");
        builder.append("上传原因/流水号:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("图像ID:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("摄像头ID:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("位置图像数据大小:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("偏移量:"+cmd.readInt(4));
        builder.append("\r\n");

        builder.append("图像数据："+cmd.readBCD(cmd.leftSize()));

        return builder.toString();
    }
}
